package com.oracle.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oracle.compents.PageResult;
import com.oracle.mapper.PhPartnerMapper;
import com.oracle.pojo.PhPartner;
import com.oracle.pojo.PhPartnerExample;
import com.oracle.pojo.PhPartnerExample.Criteria;
import com.oracle.service.PartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class PartnerServiceImpl implements PartnerService {

	@Autowired
	private PhPartnerMapper partnerMapper;

	/**
	 * 查询全部
	 */
	@Override
	public List<PhPartner> findAll() {
		return partnerMapper.selecPhyExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		Page<PhPartner> page=   (Page<PhPartner>) partnerMapper.selecPhyExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(PhPartner partner) {
		partnerMapper.insert(partner);
	}


	/**
	 * 修改
	 */
	@Override
	public void update(PhPartner partner){
		partnerMapper.updateByPrimaryKey(partner);
	}

	/**
	 * 根据ID获取实体
	 * @param id
	 * @return
	 */
	@Override
	public PhPartner findOne(Integer id){
		return partnerMapper.selecPhyPrimaryKey(id);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(Integer[] ids) {
		for(Integer id:ids){
			partnerMapper.deleteByPrimaryKey(id);
		}
	}


		@Override
	public PageResult findPage(PhPartner partner, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);

		PhPartnerExample example=new PhPartnerExample();
		Criteria criteria = example.createCriteria();

		if(partner!=null){
						if(partner.getUname()!=null && partner.getUname().length()>0){
				criteria.andUnameLike("%"+partner.getUname()+"%");
			}			if(partner.getPetphoto()!=null && partner.getPetphoto().length()>0){
				criteria.andPetphotoLike("%"+partner.getPetphoto()+"%");
			}			if(partner.getPetphotolist()!=null && partner.getPetphotolist().length()>0){
				criteria.andPetphotolistLike("%"+partner.getPetphotolist()+"%");
			}			if(partner.getPetname()!=null && partner.getPetname().length()>0){
				criteria.andPetnameLike("%"+partner.getPetname()+"%");
			}			if(partner.getPetmatchrequire()!=null && partner.getPetmatchrequire().length()>0){
				criteria.andPetmatchrequireLike("%"+partner.getPetmatchrequire()+"%");
			}			if(partner.getCreatetime()!=null && partner.getCreatetime().length()>0){
				criteria.andCreatetimeLike("%"+partner.getCreatetime()+"%");
			}
		}

		Page<PhPartner> page= (Page<PhPartner>)partnerMapper.selecPhyExample(example);
		return new PageResult(page.getTotal(), page.getResult());
	}

}
